<%@include file="/WEB-INF/pages/commons/commons.jsp" %>
<%@ page import="java.io.StringWriter" %>
<%@ page import="java.io.PrintWriter" %>

<stripes:layout-definition>
    <stripes:layout-render name="${_themePath}/base-layout.jsp" _title="${_title}">
        <stripes:layout-component name="_head">
            <script type="text/javascript">
                // === manageHeaderMenu
                YAHOO.util.Event.onContentReady("manageHeaderMenu", function() {
                    var manageHeaderMenu = new YAHOO.widget.Button("manageHeaderMenuButton",
                                            { type: "menu", menu: "manageHeaderMenuButtonSelect" });
                    //	"click" event listener for the second Button's Menu instance
                    var onMenuClick = function (p_sType, p_aArgs) {
                        var oEvent = p_aArgs[0];	//	DOM event
                        var oMenuItem = p_aArgs[1];	//	MenuItem instance that was the
                                                    //	target of the event
                        if (oMenuItem) {
                            if ('0' == oMenuItem.value) {   // user
                                document.location.href = '<stripes:url beanclass="foo.bar.wiki.web.action.user.ListUsersActionBean" event="view"/>';
                            }
                            else if ('1' == oMenuItem.value) {   // wiki
                                document.location.href = '<stripes:url beanclass="foo.bar.wiki.web.action.general.DashboardActionBean" event="view"/>';
                            }
                            else {
                                alert('unrecognized menu option');
                            }
                        }
                    };
                    //	Add a "click" event listener for the Button's Menu
                    manageHeaderMenu.getMenu().subscribe("click", onMenuClick);
                });



                // === userHeaderMenu
                YAHOO.util.Event.onContentReady("userHeaderMenu", function() {
                    var userHeaderMenu = new YAHOO.widget.Button("userHeaderMenuButton",
                                            { type: "menu", menu: "userHeaderMenuButtonSelect"});
                    var onMenuClick = function(p_sType, p_aArgs) {
                        var oEvent = p_aArgs[0];        // DOM event
                        var oMenuItem = p_aArgs[1];     // MenuItem instance that was the target of the event
                        if (oMenuItem) {
                            if ('0' == oMenuItem.value) {  // profile
                                document.location.href='<stripes:url beanclass="foo.bar.wiki.web.action.user.EditProfileActionBean" event="view"/>';
                            }
                            else if ('1' == oMenuItem.value) {  // logout
                                document.location.href='<stripes:url beanclass="foo.bar.wiki.web.action.user.LogoutActionBean" event="logout"/>';
                            }
                            else {
                                alert('unrecongnized menu option');
                            }
                        }
                    }
                    userHeaderMenu.getMenu().subscribe("click", onMenuClick);
                });
            </script>
            <c:out value="${_head}" escapeXml="false"/>
        </stripes:layout-component>
        <stripes:layout-component name="_topHeader">
            <jsecurity:authenticated>
                Welcome <b>${_user.username}</b>
                <span>|</span>
            </jsecurity:authenticated>
            <span id="manageHeaderMenu">
                <input type="button" id="manageHeaderMenuButton" value="Manage"/>
                <select id="manageHeaderMenuButtonSelect">
                    <foobarwiki:hasAnyPermissions name="user:view:*|user:edit:*|user:remove:*">
                        <option value="0">User</option>
                    </foobarwiki:hasAnyPermissions>
                    <option value="1">Dashboard</option>
                </select>
            </span>
            <jsecurity:authenticated>
                <span>|</span>
                <span id="userHeaderMenu">
                    <input type="button" id="userHeaderMenuButton" value="${_user.username}"/>
                    <select id="userHeaderMenuButtonSelect">
                        <jsecurity:hasPermission name="user:ownProfile:${_user.id}">
                            <option value="0">Profile</option>
                        </jsecurity:hasPermission>
                        <option value="1">Logout</option>
                    </select>
                </span>
            </jsecurity:authenticated>
            <jsecurity:notAuthenticated>
                <span>|</span>
                <stripes:link beanclass="foo.bar.wiki.web.action.general.LoginActionBean" event="view">
                    Login
                </stripes:link>
                <jsecurity:hasPermission name="user:signup:*">
                    <span>|</span>
                    <stripes:link beanclass="foo.bar.wiki.web.action.general.SignupActionBean" event="view">
                        Signup
                    </stripes:link>
                </jsecurity:hasPermission>
            </jsecurity:notAuthenticated>
        </stripes:layout-component>
        <stripes:layout-component name="_bottomHeader">
            <DIV id="logo">
                <!--
                   Put logo image here 
                -->
            </DIV>
            <DIV id="search">
                <c:out value="${_bottomHeader}" escapeXml="false"/>
            </DIV> <!-- end search -->
        </stripes:layout-component>
        <stripes:layout-component name="_topNav"><c:out value="${_topNav}" escapeXml="false"/></stripes:layout-component>
        <stripes:layout-component name="_content"><c:out value="${_content}" escapeXml="false"/></stripes:layout-component>
        <stripes:layout-component name="_footer">
            &copy;2009 FooBarWiki -
            <A href="http://www.code.google.com/p/foobarwiki">Home</A> -
            <A href="http://code.google.com/p/foobarwiki/issues/list">Issue Tracker</A> -
            <A href="http://code.google.com/p/foobarwiki/w/list">Documentations</A> 
            <BR> <BR>
            Released under <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache License 2.0</a>
        </stripes:layout-component>
    </stripes:layout-render>
</stripes:layout-definition>




